#Arnaud Aujon 	AUJA31018906

CC=gcc
CFLAGS =-O0 -Wall -lm

OCAMLC=ocamlc
OCAMLLEX=ocamllex
OCAMLYACC=ocamlyacc

PROG=compiler
C_FILE=out.c
BIN_FILE=a.out

# list of object
PROG_OBJS=type.cmo grammar.cmo lexer.cmo variable.cmo opt1.cmo \
opt2.cmo object.cmo move.cmo inference.cmo main.cmo

all:
	$(OCAMLC) -c type.ml
	$(OCAMLLEX) lexer.mll	
	$(OCAMLYACC) grammar.mly
	$(OCAMLC) -c grammar.mli
	$(OCAMLC) -c lexer.ml
	$(OCAMLC) -c grammar.ml
	$(OCAMLC) -c variable.ml
	$(OCAMLC) -c opt1.ml
	$(OCAMLC) -c opt2.ml
	$(OCAMLC) -c object.ml
	$(OCAMLC) -c move.ml
	$(OCAMLC) -c inference.ml
#	$(OCAMLC) -c display.ml
	$(OCAMLC) -c main.ml
	$(OCAMLC) -o $(PROG) $(PROG_OBJS)

clean: 
	rm -f $(PROG)
	rm -f *.cm[iox]
	rm -f grammar.ml
	rm -f grammar.mli
	rm -f lexer.ml
	rm -f out.c
	rm -f *.o

test_opt1:
	./$(PROG) opt1.rb out.c

test_opt2:
	./$(PROG) opt2.rb out.c

test_opt3:
	./$(PROG) opt3.rb out.c

test_function:
	./$(PROG) test_function.rb out.c

test_for:
	./$(PROG) test_for.rb out.c

test_pow:
	./$(PROG) test_pow.rb out.c

array:
	./$(PROG) array.rb out.c

cp:
	$(CC) $(CFLAGS) out.c
	./$(BIN_FILE)

bench1:
	echo "time for our compiler"
	./$(PROG) benchmark1.rb benchmark1.c 
	$(CC) $(CFLAGS) benchmark1.c -o benchmark1
	time -p ./benchmark1 > /dev/null
	echo "time for ruby interpreter"
	time -p ruby benchmark1.rb > /dev/null
